package com.ruoyi.system.schedule;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.QzStation;
import com.ruoyi.system.mapper.QzStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 干扰库台站静态数据定时插入
 * @author soulmate丶
 * @date 2021-08-05
 */
@EnableScheduling
@Component
public class StationAdd {

    @Autowired
    private QzStationMapper qzStationMapper;

    //每天凌晨1点定时插入昨日静态数据
    @Scheduled(cron = "0 0 1 * * ?")
    public void syn() {
        QueryWrapper<QzStation> queryWrapper = new QueryWrapper<>();
        String Byesterday = DateUtils.getBYesterday();
        System.out.println(Byesterday);
        queryWrapper.like("create_time", Byesterday);
        List<QzStation> qzStationList = qzStationMapper.selectList(queryWrapper);
        System.out.println(qzStationList.size());
        List<QzStation> nowList = new ArrayList<>();
        double avgTime = 0;
        long startTime = System.currentTimeMillis();
        for (QzStation qzStation : qzStationList) {
            QzStation qz = new QzStation();
            qz.setDeptId(qzStation.getDeptId());
            qz.setStaName(qzStation.getStaName());
            qz.setTestName(qzStation.getTestName());
            qz.setCreateBy("admin");
            qz.setRemark("无");
            qz.setOperator("admin");
            qz.setCreateTime(DateUtils.getYesterday());
            nowList.add(qz);
            qzStationMapper.insert(qz);
        }
        avgTime = (System.currentTimeMillis() - startTime) / 1000.0 / 10.0;
        System.out.println(avgTime);
    }
}
